﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.ProductionWorking;
using MangoMes.Commont.Domain.Suppliers;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace ManagoMes.Read.API.Applications.ProductionRead
{
    public class ProductionTypeShowHandler : IRequestHandler<ProductionTypeShowCommand, ResultsDTO<ProductionType>>
    {
        private readonly IBateRepository<ProductionType> _ProductionTypeRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productionTypeRepository"></param>
        public ProductionTypeShowHandler(IBateRepository<ProductionType> productionTypeRepository)
        {
            _ProductionTypeRepository = productionTypeRepository;
        }
        /// <summary>
        /// 生产报工类型绑定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO<ProductionType>> Handle(ProductionTypeShowCommand request, CancellationToken cancellationToken)
        {
            DapperHelper dapperHelper = new DapperHelper();
            ProductionType productionType = new ProductionType();
            ResultsDTO<ProductionType> res = new ResultsDTO<ProductionType> { Code = 0 };
            string conn = dapperHelper.MangoMesRead;
            string str = "select * from productiontype";
            res.Data = _ProductionTypeRepository.GetAll(str, productionType, conn).ToList();
            return res;
        }
    }
}
